/**
 * Created by LeungZ on 2016/8/8.
 */
import './overview.scss';
import temp from './overview.html';
import ctrl from './overview.ctrl.js';

export default angular.module('ctg-k8sconsole').config(['$stateProvider', $stateProvider => {
    $stateProvider.state('k8s-overview', {
        url: '/k8s/overview?kDbCode',
        templateUrl: temp,
        controller: ctrl,
        controllerAs: 'ov',
        resolve: {
            // cluster: ['clusterSrv', 'ctgNotification', '$stateParams',
            //     function(clusterSrv, ctgNotification, $stateParams) {
            //         return clusterSrv.getClusterInfo($stateParams.kDbCode).catch(function(data) {
            //             ctgNotification.error('获取概览详细数据有误.');
            //         });
            //     }
            // ],
            node: ['nodeSrv', 'ctgNotification', '$stateParams', function(nodeSrv, ctgNotification, $stateParams) {
                return nodeSrv.getNodeList({ perPage: 18, page: 1, code: $stateParams.kDbCode }).catch(function(data) {
                    ctgNotification.error('获取宿主机列表数据有误.');
                });
            }],
            dp: ['serviceSrv', 'ctgNotification', '$stateParams', function (serviceSrv, ctgNotification, $stateParams) {
                return serviceSrv.getDPList({page: 1, code: $stateParams.kDbCode,perPage:99}).catch(function (data) {
                    ctgNotification.error('获取dp服务列表数据有误.');
                });
            }],
            lessee: ['LesseeSrv', 'ctgNotification', '$stateParams', function(LesseeSrv, ctgNotification, $stateParams) {
                return LesseeSrv.getRCList({ page: 1, code: $stateParams.kDbCode,perPage:99 }).catch(function(data) {
                    ctgNotification.error('获取租户列表数据有误.');
                });
            }],
            nodeResource: ['node', 'nodeSrv', 'ctgNotification', '$stateParams', function(node, nodeSrv, ctgNotification, $stateParams) {
                let nodeArr = [];
                if (node) {
                    angular.forEach(node.nodes, (ele) => {
                        nodeArr.push(ele.nodeIp)
                    })
                    return nodeSrv.queryNodeResource({ clusterCode: $stateParams.kDbCode, nodeips: nodeArr }).catch(function(data) {
                        ctgNotification.error('获取节点动态资源有误.');
                    });
                }
            }],
            detail: ['clusterSrv', 'ctgNotification', '$stateParams',
                function(clusterSrv, ctgNotification, $stateParams) {
                    return clusterSrv.getClusterList({
                        clusterCode: $stateParams.kDbCode,
                        perPage: 1,
                        currentPage: 1
                    });
                }
            ]
        }
    })
}]);